package com.hspedu.newData.dmsxl.滑动窗口;

import java.util.HashSet;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC1456定长子串中元音的最大数目 {

    // todo 效率太低了
    public int maxVowels(String s, int k) {

        HashSet<Character> set = new HashSet<>();
        set.add('a');
        set.add('e');
        set.add('i');
        set.add('o');
        set.add('u');

        int slow = 0;
        int fast = k;
        int count = 0;
        for (int i = slow; i < fast; i++) {
            if (set.contains(s.charAt(i))){
                count++;
            }
        }

        if (count == k) return k;
        int x = count;
        for (int i = fast; i < s.length(); i++) {
            if (set.contains(s.charAt(slow++))){
                count--;
            }
            if (set.contains(s.charAt(i))){
                count++;
            }
            x = Math.max(x,count);
            if (x == k){
                return k;
            }
        }
        return x;
    }
}
